package com.smap.common;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.MouseEvent;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.event.dom.client.MouseWheelEvent;
import com.google.gwt.event.dom.client.MouseWheelHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Widget;

public abstract class MouseAdapter implements MouseOverHandler,
		MouseOutHandler, MouseMoveHandler, MouseDownHandler, MouseUpHandler,
		MouseWheelHandler {

	public void onMouseWheel(MouseWheelEvent event) {
		onEvent(event);
	}

	public void onMouseUp(MouseUpEvent event) {
		onEvent(event);

	}

	public void onMouseDown(MouseDownEvent event) {
		onEvent(event);
	}

	public void onMouseMove(MouseMoveEvent event) {
		onEvent(event);
	}

	public void onMouseOut(MouseOutEvent event) {
		onEvent(event);
	}

	public void onMouseOver(MouseOverEvent event) {
		onEvent(event);
	}

	List<HandlerRegistration> handlers = new ArrayList<HandlerRegistration>();

	public void install(Widget widget) {
		System.out.println("install");
		handlers.add(widget.addDomHandler(this, MouseOverEvent.getType()));
		handlers.add(widget.addDomHandler(this, MouseOutEvent.getType()));
		handlers.add(widget.addDomHandler(this, MouseMoveEvent.getType()));
		handlers.add(widget.addDomHandler(this, MouseDownEvent.getType()));
		handlers.add(widget.addDomHandler(this, MouseUpEvent.getType()));
		handlers.add(widget.addDomHandler(this, MouseWheelEvent.getType()));

	}

	public void remove() {
		System.out.println("remove");
		for (HandlerRegistration link : handlers) {
			link.removeHandler();
		}

	}

	public abstract void onEvent(@SuppressWarnings("rawtypes") MouseEvent evt);
}